package com.tensquare.gathering.controller;

import com.tensquare.gathering.pojo.Gathering;
import com.tensquare.gathering.service.GatheringService;
import entity.Result;
import entity.StatusCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Macross
 * @Type GatheringController.java
 * @Desc
 * @date 2019/12/17 20:34
 */
@RestController
@RequestMapping("/gathering")
@Api(value = "活动信息管理控制器")
public class GatheringController {

    @Autowired
    private GatheringService gatheringService;

    /**
     * 获取指定id的活动信息
     * @param gatheringId 活动id
     * @return
     */
    @GetMapping("/{gatheringId}")
    @ApiOperation(value = "获取指定活动信息")
    public Result<Gathering> findById(@PathVariable @ApiParam(value = "活动id",required = true) String gatheringId){
        return new Result<>(true,StatusCode.OK,"查询成功",gatheringService.findById(gatheringId));
    }

    /**
     * 更新活动信息
     * @param gatheringId 活动id
     * @param gathering 活动信息
     * @return
     */
    @PutMapping("/{gatheringId}")
    @ApiOperation(value = "更新活动信息",notes = "更新数据库活动信息,并清除对应的文章信息缓存")
    public Result updateGathering(@PathVariable @ApiParam(value = "活动id",required = true) String gatheringId,
                                  @RequestBody  @ApiParam(value = "活动信息",required = true) Gathering gathering){
        gathering.setId(gatheringId);
        gatheringService.updateGathering(gathering);
        return new Result<>(true,StatusCode.OK,"操作成功");
    }

    /**
     * 删除活动信息
     * @param gatheringId 活动id
     * @return
     */
    @DeleteMapping("/{gatheringId}")
    @ApiOperation(value = "删除活动信息",notes = "删除数据库活动信息,并清除对应的文章信息缓存")
    public Result deleteGathering(@PathVariable @ApiParam(value = "活动id",required = true) String gatheringId){
        gatheringService.deleteGathering(gatheringId);
        return new Result<>(true,StatusCode.OK,"操作成功");
    }
}
